/***********************************************************************
 * Module:  ControlVehicleController.java
 * Author:  Administrator
 * Purpose: Defines the Class ControlVehicleController
 ***********************************************************************/

package ishitong.rvims.control.controller;

import ishitong.rvims.control.service.ControlVehicleService;
import ishitong.rvims.control.service.ControlTypeService;
import ishitong.rvims.basic.service.LicencePlateTypeService;
import ishitong.rvims.basic.service.VehicleTypeService;
import ishitong.rvims.basic.service.LicencePlateKindService;
import ishitong.rvims.basic.service.LicencePlateColourService;
import ishitong.rvims.basic.service.VehicleColourService;
import ishitong.rvims.control.service.ControlTaskToVehicleService;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ishitong.core.common.SQLSelectWhere;
import ishitong.rvims.domain.control.ControlVehicle;
import ishitong.rvims.domain.control.ControlTask;
import ishitong.rvims.domain.control.ControlType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ishitong.rvims.domain.basic.LicencePlateColour;
import ishitong.rvims.domain.basic.LicencePlateKind;
import ishitong.rvims.domain.basic.LicencePlateType;
import ishitong.rvims.domain.basic.VehicleColour;
import ishitong.rvims.domain.basic.VehicleType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import ishitong.core.common.ActionController;

/** @pdOid 4afc4686-0e93-4cd5-a254-c951ef8fcdde */
@Controller
public class ControlVehicleController extends ActionController {
   /** @pdOid c3ade95b-7d3f-4289-b9c7-fd7682641cf6
       @pdRoleInfo migr=yes name=ControlVehicleService assc=association2 */
   @Autowired
   private ControlVehicleService controlVehicleService;
   /** @pdOid 4b6a5fb2-1226-4f9b-b0b6-19f331050a53
       @pdRoleInfo migr=yes name=ControlTypeService assc=association3 */
   @Autowired
   private ControlTypeService controlTypeService;
   /** @pdOid 0af32079-70fc-4e05-9c03-8ec767b97075
       @pdRoleInfo migr=yes name=LicencePlateTypeService assc=association4 */
   @Autowired
   private LicencePlateTypeService licencePlateTypeService;
   /** @pdOid ee19948c-5680-4a62-9523-3cf0de430e7c
       @pdRoleInfo migr=yes name=VehicleTypeService assc=association8 */
   @Autowired
   private VehicleTypeService vehicleTypeService;
   /** @pdOid bd22ff89-acc0-4dc5-9466-d1539cc47eda
       @pdRoleInfo migr=yes name=LicencePlateKindService assc=association9 */
   @Autowired
   private LicencePlateKindService licencePlateKindService;
   /** @pdOid 6aa97067-c0c0-4cce-88ee-3a18d923d4aa
       @pdRoleInfo migr=yes name=VehicleColourService assc=association11 */
   @Autowired
   private VehicleColourService vehicleColourService;
   /** @pdOid c623010f-981f-4abc-9b72-f7feece98535
       @pdRoleInfo migr=yes name=LicencePlateColourService assc=association10 */
   @Autowired
   private LicencePlateColourService licencePlateColourService;
   /** @pdOid 3ae1fd25-54c3-40e1-9bd2-ca84664fa296
       @pdRoleInfo migr=yes name=ControlTaskToVehicleService assc=association12 */
   @Autowired
   private ControlTaskToVehicleService controlTaskToVehicleService;
   
   /** @pdOid a06a3839-8b0b-4ed6-9030-199e00204205 */
   private void initialData() {
      // TODO: implement
   }
   
   /** @param request 
    * @param response
    * @exception Exception
    * @pdOid ec9e04ca-f45f-4db4-8746-7c130226f09d */
   @RequestMapping(value = "/ajaxShowControlVehicleDialog.do")
   public ModelAndView handleAjaxShowControlVehicleDialog(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try{
     Map<String,Object> model= new HashMap<String,Object>();
     List<LicencePlateKind> listLicencePlateKind= licencePlateKindService.findLicencePlateKindList(null);
     List<ControlType> listControlType= controlTypeService.findControlTypeList(null);
     model.put("listLicencePlateKind", listLicencePlateKind);
     model.put("listControlType", listControlType);
     return new ModelAndView("control/ControlVehicleDialog",model);
    }catch(Exception e){
     e.printStackTrace();
    }
      return null;
   }
   
   /** @param request 
    * @param response 
    * @param sQLSelectWhere
    * @exception Exception
    * @pdOid 7f535dd1-2d4e-457c-9775-49179526e326 */
   @RequestMapping(value = "/ajaxFindControlVehicleListForSelect.do")
   public ModelAndView handleAjaxFindControlVehicleListForSelect(HttpServletRequest request, HttpServletResponse response, SQLSelectWhere sQLSelectWhere) throws Exception {
   try {
   	Map<String, Object> model = new HashMap<String, Object>();
   	List<ControlVehicle> listControlVehicle = controlVehicleService.findControlVehicleList(sQLSelectWhere);
   	model.put("listControlVehicle", listControlVehicle);
   	return new ModelAndView("control/ControlVehicleListForSelect", model);
   } catch (Exception e) {
   	e.printStackTrace();
   }
       return null;
    }
   
   /** @param request 
    * @param response
    * @exception Exception
    * @pdOid ef589c24-c60f-4523-b9fb-0be4744dec50 */
   @RequestMapping(value = "/showControlVehicleSearch.do")
   public ModelAndView handleShowControlVehicleSearch(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try{
       Map<String,Object> model= new HashMap<String,Object>();
       List<LicencePlateType> listLicencePlateType= licencePlateTypeService.findLicencePlateTypeList(null);
       List<ControlType> listControlType= controlTypeService.findControlTypeList(null);
       List<VehicleType> listVehicleType= vehicleTypeService.findVehicleTypeList();
       model.put("listLicencePlateType", listLicencePlateType);
       model.put("listControlType", listControlType);
       model.put("listVehicleType", listVehicleType);
       return new ModelAndView("control/ControlVehicleSearch",model);
      }catch(Exception e){
       e.printStackTrace();
      }
      return null;
   }
   
   /** @param request 
    * @param response 
    * @param sQLSelectWhere
    * @exception Exception
    * @pdOid 938919ab-8fa2-4f87-af65-16f9c035617d */
   @RequestMapping(value = "/ajaxControlVehicleSearchList.do")
   public ModelAndView handleAjaxControlVehicleSearchList(HttpServletRequest request, HttpServletResponse response, SQLSelectWhere sQLSelectWhere) throws Exception {
    try {
     	Map<String, Object> model = new HashMap<String, Object>();
     	List<ControlVehicle> listControlVehicle = controlVehicleService.findControlVehicleList(sQLSelectWhere);
     	sQLSelectWhere.setRecordCount(controlVehicleService.getControlVehicleTotal(sQLSelectWhere));
     	model.put("listControlVehicle", listControlVehicle);
     	model.put("sQLSelectWhere", sQLSelectWhere);
     	return new ModelAndView("control/ControlVehicleSearchList", model);
     } catch (Exception e) {
     	e.printStackTrace();
     }
      return null;
   }
   
   /** @param request 
    * @param response
    * @exception Exception
    * @pdOid 078fc676-a5d7-4a24-923a-a9d6deaf6bd0 */
   @RequestMapping(value = "/showControlVehicleAdd.do")
   public ModelAndView handleShowControlVehicleAdd(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
      	Map<String, Object> model = new HashMap<String, Object>();
      	List<VehicleType> listVehicleType = vehicleTypeService.findVehicleTypeList();
      	model.put("listVehicleType", listVehicleType);
      	List<LicencePlateType> listLicencePlateType= licencePlateTypeService.findLicencePlateTypeList(null);
      	model.put("listLicencePlateType", listLicencePlateType);
      	List<LicencePlateKind> listLicencePlateKind= licencePlateKindService.findLicencePlateKindList(null);
      	model.put("listLicencePlateKind", listLicencePlateKind);
      	List<VehicleColour> listVehicleColour = vehicleColourService.findVehicleColourList();
      	model.put("listVehicleColour", listVehicleColour);
      	List<LicencePlateColour> listLicencePlateColour = licencePlateColourService.findLicencePlateColourList();
      	model.put("listLicencePlateColour", listLicencePlateColour);
      	List<ControlType> listControlType= controlTypeService.findControlTypeList(null);
      	model.put("listControlType", listControlType);
      	return new ModelAndView("control/ControlVehicleEdit", model);
      } catch (Exception e) {
      	e.printStackTrace();
      }
      return null;
   }
   
   /** @param request 
    * @param response 
    * @param controlVehicleId
    * @exception Exception
    * @pdOid fae11cdf-665d-4d3d-9b06-9c05f94c91b6 */
   @RequestMapping(value = "/showControlVehicleEdit.do")
   public ModelAndView handleShowControlVehicleEdit(HttpServletRequest request, HttpServletResponse response, String controlVehicleId) throws Exception {
    try {
     	Map<String, Object> model = new HashMap<String, Object>();
     	ControlVehicle controlVehicle = controlVehicleService.getControlVehicleById(controlVehicleId);
     	model.put("controlVehicle", controlVehicle);
      	List<VehicleType> listVehicleType = vehicleTypeService.findVehicleTypeList();
      	model.put("listVehicleType", listVehicleType);
      	List<LicencePlateType> listLicencePlateType= licencePlateTypeService.findLicencePlateTypeList(null);
      	model.put("listLicencePlateType", listLicencePlateType);
      	List<LicencePlateKind> listLicencePlateKind= licencePlateKindService.findLicencePlateKindList(null);
      	model.put("listLicencePlateKind", listLicencePlateKind);
      	List<VehicleColour> listVehicleColour = vehicleColourService.findVehicleColourList();
      	model.put("listVehicleColour", listVehicleColour);
      	List<LicencePlateColour> listLicencePlateColour = licencePlateColourService.findLicencePlateColourList();
      	model.put("listLicencePlateColour", listLicencePlateColour);
      	List<ControlType> listControlType= controlTypeService.findControlTypeList(null);
      	model.put("listControlType", listControlType);
      	List<ControlTask> listControlTask = controlTaskToVehicleService.findControlTaskByControlVehicleId(controlVehicleId);
     	model.put("listControlTask", listControlTask);
     	return new ModelAndView("control/ControlVehicleEdit", model);
     } catch (Exception e) {
     	e.printStackTrace();
     }
      return null;
   }
   
   /** @param request 
    * @param response 
    * @param controlVehicle 
    * @param strBeginTime 
    * @param strEndTime
    * @exception Exception
    * @pdOid 32f45b35-e4b8-439e-9fb7-76f824cf9fcf */
   @RequestMapping(value = "/saveControlVehicle.do",method = RequestMethod.POST)
   public ModelAndView handleSaveControlVehicle(HttpServletRequest request, HttpServletResponse response, ControlVehicle controlVehicle, String strBeginTime, String strEndTime) throws Exception {
    try {
     controlVehicle.setBeginTime(SQLSelectWhere.StringToDate(strBeginTime, null));
     controlVehicle.setEndTime(SQLSelectWhere.StringToDate(strEndTime, null));
     controlVehicleService.saveControlVehicle(controlVehicle);
     	return new ModelAndView("redirect:showControlVehicleSearch.do");
     } catch (Exception e) {
     	e.printStackTrace();
     }
          return null;
   }
   
   /** @param request 
    * @param response 
    * @param controlVehicleId
    * @exception Exception
    * @pdOid 4cca3baf-0d33-4da0-a9e2-46f0fa336f42 */
   @RequestMapping(value = "/showControlVehicleView.do")
   public ModelAndView handleShowControlVehicleView(HttpServletRequest request, HttpServletResponse response, String controlVehicleId) throws Exception {
    try {
     	Map<String, Object> model = new HashMap<String, Object>();
     	ControlVehicle controlVehicle = controlVehicleService.getControlVehicleById(controlVehicleId);
     	model.put("controlVehicle", controlVehicle);
     	List<ControlTask> listControlTask = controlTaskToVehicleService.findControlTaskByControlVehicleId(controlVehicleId);
     	model.put("listControlTask", listControlTask);
     	return new ModelAndView("control/ControlVehicleView", model);
     } catch (Exception e) {
     	e.printStackTrace();
     }
      return null;
   }
   
   /** @param request 
    * @param response 
    * @param controlVehicleIds
    * @exception Exception
    * @pdOid e7c53846-323c-496b-8d15-86f85f414c9b */
   @RequestMapping(value = "/ajaxDeleteControlVehicleByIds.do")
   public String handleAjaxDeleteControlVehicleByIds(HttpServletRequest request, HttpServletResponse response, String controlVehicleIds) throws Exception {
    try {
     controlVehicleService.deleteControlVehicleByIds(controlVehicleIds);
        return null;
     } catch (Exception e) {
     	e.printStackTrace();
     } 	
      return null;
   }

}